//
//  NSString+QSCategory.h
//  QSCategoriesOC_Example
//
//  Created by SQ on 2019/12/18.
//  Copyright © 2019 QiaoShi. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface NSString (QSCategory)

#pragma mark - Hash
- (nullable NSString *)qs_md2String;
- (nullable NSString *)qs_md5String;
- (nullable NSString *)qs_md4String;

- (nullable NSString *)qs_sha1String;
- (nullable NSString *)qs_sha224String;
- (nullable NSString *)qs_sha256String;
- (nullable NSString *)qs_sha384String;
- (nullable NSString *)qs_sha512String;

- (nullable NSString *)qs_crc32String;

- (nullable NSString *)qs_hmacMD5StringWithKey:(NSString *)key;
- (nullable NSString *)qs_hmacSHA1StringWithKey:(NSString *)key;
- (nullable NSString *)qs_hmacSHA224StringWithKey:(NSString *)key;
- (nullable NSString *)qs_hmacSHA256StringWithKey:(NSString *)key;
- (nullable NSString *)qs_hmacSHA384StringWithKey:(NSString *)key;
- (nullable NSString *)qs_hmacSHA512StringWithKey:(NSString *)key;

#pragma mark - Encode and decode
- (nullable NSString *)qs_base64EncodedString;
+ (nullable NSString *)qs_stringWithBase64EncodedString:(NSString *)base64EncodedString;

- (NSString *)qs_stringByURLEncode;
- (NSString *)qs_stringByURLDecode;

- (NSString *)qs_stringByEscapingHTML;

#pragma mark - Drawing
- (CGSize)qs_sizeForFont:(UIFont *)font size:(CGSize)size mode:(NSLineBreakMode)lineBreakMode;
- (CGFloat)qs_widthForFont:(UIFont *)font;
- (CGFloat)qs_heightForFont:(UIFont *)font width:(CGFloat)width;

#pragma mark - Regular Expression
- (BOOL)qs_matchesRegex:(NSString *)regex options:(NSRegularExpressionOptions)options;
- (void)qs_enumerateRegexMatches:(NSString *)regex
                      options:(NSRegularExpressionOptions)options
                   usingBlock:(void (^)(NSString *match, NSRange matchRange, BOOL *stop))block;
- (NSString *)qs_stringByReplacingRegex:(NSString *)regex
                             options:(NSRegularExpressionOptions)options
                          withString:(NSString *)replacement;

#pragma mark - Utilities

- (NSString *)qs_stringByTrim; // 去掉头部和尾部的空白字符(空格、换行)
/**
 nil, @"", @"  ", @"\n" will Returns NO; otherwise Returns YES.
 */
- (BOOL)qs_isNotBlank;
- (nullable NSData *)qs_dataValue;
- (NSRange)qs_rangeOfAll;
- (nullable id)qs_jsonValueDecoded;
- (void)qs_enumerateUTF32CharInRange:(NSRange)range usingBlock:(void (^)(UTF32Char char32, NSRange range, BOOL *stop))block;

+ (NSString *)qs_stringWithUUID;
+ (nullable NSString *)qs_stringWithUTF32Char:(UTF32Char)char32;
+ (nullable NSString *)qs_stringWithUTF32Chars:(const UTF32Char *)char32 length:(NSUInteger)length;
+ (nullable NSString *)qs_stringPathNamed:(NSString *)name;

@end

NS_ASSUME_NONNULL_END
